﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.IO;

namespace login
{
    [DataContractAttribute]
    class SocialRelationModel
    {
        public SocialRelationModel(){

        }

        [DataMember]
        public string Appellation { get; set; }

        [DataMember]
        public string Name { get; set; }

        [DataMember]
        public int Age { get; set; }

        [DataMember]
        public string Company_And_Phone { get; set; }

        public string EntityToJson(List<SocialRelationModel> entity)
        {
            DataContractSerializer serializer = new DataContractSerializer(entity.GetType());
            using (MemoryStream stream = new MemoryStream())
            {
                serializer.WriteObject(stream, entity);
                return Encoding.UTF8.GetString(stream.ToArray());
            }

        }

        public List<SocialRelationModel> JsonToEntity(string jsonstring)
        {
            DataContractSerializer serializer = new DataContractSerializer(typeof(List<SocialRelationModel>));
            using (MemoryStream mStream = new MemoryStream(Encoding.UTF8.GetBytes(jsonstring)))
            {
                return serializer.ReadObject(mStream) as List<SocialRelationModel>;
            }
        }
    }
}
